package com.lk.springboot.dao;

import com.lk.springboot.pojo.SmallPhoto;
import com.lk.springboot.pojo.Ticket;
import com.lk.springboot.pojo.USHave;
import com.lk.springboot.vo.GameSP;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lk
 * @date 2020/1/10 0010 22:21
 */
@Mapper
public interface GameMapper {

    @Select("select s_id from sites,photo where sp_id=#{sp_id} and sites.p_id=photo.p_id ")
    String getSitesBySp(String sp_id);

    // 增加用户的拼图拥有记录
    @Insert("insert into u_s_have(u_id,s_id,sp_id) values(#{u_id},#{s_id},#{sp_id})")
    void addPhoto(USHave usHave);

    // 根据 站点id 和 稀有度 摘取拼图id+url
    @Select("select photo.sp_id,url from photo,smallphoto where p_id=#{p_id} and tags<=4 and rare=#{rare} and photo.sp_id=smallphoto.sp_id")
    GameSP getSmallPhoto(@Param("p_id") String p_id, @Param("rare") String rare);

    // 增加积分
    @Update("update users set scores = scores + #{score_num} where u_id = #{u_id}")
    void addScore(@Param("u_id") String u_id, @Param("score_num") int score_num);

    // 玩一次游戏,加一次进度,当任务进度等于总进度时，不再增加进度
    @Update("update u_t_solve set speed = speed + 1 where  u_id=#{u_id} and t_id = 't10005' and speed < 3 ")
    void signGame(String u_id);

    // 获取用户线下游戏最高分
    @Select("select max_game_score from users where u_id=#{u_id} ")
    int getMaxGameScore(String u_id);

    // 更新用户线下游戏的最高分
    @Update("update users set max_game_score  = #{gameScore}  where u_id=#{u_id}")
    void updateMaxGameScore(@Param("u_id") String u_id, @Param("gameScore") int gameScore);

    // 根据拼图id，查询出该拼图碎片的站点名称
    @Select("select s_name from sites,photo where sp_id=#{sp_id} and photo.p_id=sites.p_id")
    String getSName(String sp_id);

    // 获取道具名
    @Select("select props_name from props where props_id = #{props_id}")
    String getPropsName(int props_id);

    // 增加用户获得的道具数目
    @Update("update user_props set num = num + 1 where u_id = #{u_id} and props_id = #{props_id} ")
    void addPropsNum(@Param("u_id") String u_id, @Param("props_id") int props_id);

    //根据sp_id获取拼图详情
    @Select("select * from smallphoto where sp_id = #{sp_id}")
    SmallPhoto getSmallPhotoBySpId(String sp_id);

    //写入vr拼图奖励
    @Insert("insert into temp(sp_id) values (#{sp_id})")
    void prepareSP(String sp_id);

    //获取vr拼图奖励
    @Select("select sp_id from temp")
    List<String> getSp();

    //清空vr奖励
    @Delete("delete from temp")
    void clearSP();

    //获取实物奖励
    @Select("select * from ticket where id = #{id}")
    Ticket getTicket(int id);

    //写一条留言
    @Insert("insert into message(content) values(#{content})")
    void insertMsg(String content);

    //获取所有留言
    @Select("select content from message ")
    ArrayList<String> getAllMsg();

}
